package com.book.warehouse.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.book.common.entity.QueryRequest;
import com.book.warehouse.entity.WarehouseHouse;
import com.book.warehouse.entity.WarehouseHouse;
import com.book.warehouse.mapper.WarehouseHouseMapper;
import com.book.warehouse.mapper.WarehouseHouseMapper;
import com.book.warehouse.service.WarehouseHouseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: 刘恬镯
 * @Description:  20174052
 */

@Service
public class WarehouseHouseServiceImpl extends ServiceImpl<WarehouseHouseMapper,WarehouseHouse> implements WarehouseHouseService{
    @Autowired
    WarehouseHouseMapper warehouseHouseMapper;

    @Override
    public List<WarehouseHouse> findWarehouseHouse(WarehouseHouse warehouseHouse) {
        QueryWrapper<WarehouseHouse> queryWrapper = new QueryWrapper<>();
        return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    public IPage<WarehouseHouse> pageWarehouseHouse(QueryRequest request, WarehouseHouse warehouseHouse) {
        QueryWrapper<WarehouseHouse> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(warehouseHouse.getHousename())) {
            queryWrapper.eq("housename", warehouseHouse.getHousename());
        }
        Page<WarehouseHouse> warehouseHouseIPage = new Page<>(request.getPageNum(), request.getPageSize());
        return this.page(warehouseHouseIPage, queryWrapper);
    }

    @Override
    public void addWarehouseHouse(WarehouseHouse warehouseHouse) {
        this.save(warehouseHouse);
    }

    @Override
    public void updateWarehouseHouse(WarehouseHouse warehouseHouse) {
        this.updateById(warehouseHouse);
    }

    @Override
    public void deleteWarehouseHouse(String[] warehouseHouse) {
        List<String> list = Arrays.asList(warehouseHouse);
        this.removeByIds(list);
    }
}
